// 获取轮播图和控制按钮的元素
var slides = document.querySelectorAll('.slide');
var prev = document.querySelector('.prev');
var next = document.querySelector('.next');

// 当前显示的图片索引
var currentIndex = 0;

// 显示指定的图片
function showSlide(index) {
    slides[currentIndex].style.display = 'none';
    currentIndex = index;
    slides[currentIndex].style.display = 'block';
}

// 自动播放
function autoPlay() {
    showSlide((currentIndex + 1) % slides.length);
    setTimeout(autoPlay, 3000); // 每3秒切换到下一张
}
autoPlay();

// 点击控制按钮时的处理
prev.addEventListener('click', function() {
    showSlide((currentIndex - 1 + slides.length) % slides.length);
});
next.addEventListener('click', function() {
    showSlide((currentIndex + 1) % slides.length);
});

